﻿#ifndef __GNUC__
#pragma execution_character_set("utf-8")
#endif

#include "{ $Node }.h"

namespace ns{ $Project }XML
{

	const QString C{ $Node }::_nodeName_ = "{ $Node }";

	C{ $Node }::C{ $Node }()
	{
		{ $For PROPS }
		propList << "{ $Prop }";
		{ $EndFor }

		{ $For SUBNODES }
		subNodes << "{ $Node }";
		{ $EndFor }
	}


	C{ $Node }::~C{ $Node }()
	{
	}

	void C{ $Node }::read(QXmlStreamReader &reader)
	{
		{ $For PROPS }
		ReadAttrib(reader, { $Prop });
		{ $EndFor }

		reader.readNext();
		while (!reader.atEnd())
		{
			if (reader.isEndElement())
			{
				reader.readNext();
				break;
			}

			if (reader.isStartElement())
			{
				{ $For SUBNODES }
				if (reader.name() == C{ $Node }::_nodeName_)
				{
					C{ $Node } _item;
					_item.read(reader);
					{ $Node }.push_back(_item);
					continue;
				}
				{ $EndFor }
		
				skipUnknownElement(reader);
			}
			else
			{
				reader.readNext();
			}
		}
	}

	void C{ $Node }::write(QXmlStreamWriter &writer)
	{
		writer.writeStartElement(_nodeName_);

		{ $For PROPS }
		WriteAttrib(writer, { $Prop });
		{ $EndFor }

		{ $For SUBNODES }
		for (auto &_item : { $Node })
			_item.write(writer);
		{ $EndFor }

		writer.writeEndElement();
	}

}
